<!--  自定义标题栏,在页面配置"navigationStyle": "custom"情况下使用,
其中标题高度和微信小程序 右侧胶囊高度保持一致 32px,以便保持title内容和胶囊居中对齐-->
<template>
  <view class="title-info" :style="'margin-top:' + menuTop + 'px'">
    <view class="v-back" v-if="leftShow" @tap="back"> 
	    <u-icon v-if="titlecolor==='#333333'"
		  name="arrow-left"
		  size="19"
	   ></u-icon>
	   <u-icon v-if="titlecolor!=='#333333'" 
	   		  color="white" name="arrow-left"
	   		  size="19"
	   ></u-icon>
    </view>
    <view class="title" :style="'color:' + titlecolor ">{{ title }}</view>	 
  </view>  
</template>
<script>
export default {
  name: "pageTitle",
  components: {},
  props: {
    title: { type: String, default: "" },
    leftShow: { type: Boolean, default: true },
	forcego: { type: Boolean, default: false },
	titlecolor: { type: String, default: "#333333" },
  },
  methods: {
    back() {
	  if(this.forcego){		 
		 uni.reLaunch({url:'/pages/home/home'}); 
	  }else{
		 
		 uni.navigateBack({}); 
	  } 
    },
    init() {
      //微信模式下获取胶囊位置
      if (process.env.UNI_PLATFORM == "mp-weixin") {
        this.title = "我是标题";
        //获取右侧胶囊的大小高度
        let rightMenuButton = uni.getMenuButtonBoundingClientRect();
        this.menuTop = rightMenuButton.top;
        console.log("胶囊位置大小:", "顶部", this.menuTop);
      }
    }

  },
  data() {
    return {
      menuTop: 24 
    };
  },
  mounted() {
    this.init();
  }
};
</script>

<style lang="scss" scoped>

.title-info {
  display: flex;
  position: relative;
  height: 32px;
  flex-direction: row;
  width: 100%;
  font-weight: bold;
  padding-bottom: 5px;
  
  border-bottom: 1px solid #66666611;


  .v-back {
    position: absolute;
    left: 16rpx;
    height: 32px;
    display: flex;
    flex-direction: row;

    .img-back {
      margin: 8px;
      width: 9px;
      height: 16px;
    }
  }

  .title {
    width: 100% !important;
    font-size: 34rpx;
    line-height: 32px;
    height: 32px;
    width: auto;
    font-family: "bold";
    color: #333333;
    text-align: center;
  }
}
</style>

